<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 基础表格</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-button type="primary" icon="el-icon-delete" class="handle-del mr10" @click="delAllSelection">批量删除
                </el-button>
                <el-select v-model="query.address" placeholder="地址" class="handle-select mr10"></el-select>

                <el-input v-model="query.name" placeholder="用户名" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>

            <el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header"
                @selection-change="handleSelectionChange">

                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column label="ID" align="center" prop="id"></el-table-column>

                <el-table-column label="路径命名空间" align="center" prop="name_with_namespace"></el-table-column>
                <el-table-column label="标签" align="center" prop="namespace.name"></el-table-column>

                <el-table-column label="SSH路径" align="center" prop="ssh_url_to_repo"></el-table-column>
                <el-table-column label="HTTP路径" align="center" prop="http_url_to_repo"></el-table-column>

                <el-table-column label="WEB路径" align="center" prop="web_url"></el-table-column>
                <el-table-column label="创建时间" align="center" prop="created_at"></el-table-column>

                <el-table-column fixed="right" label="操作" width="100">
                    <template #default="scope" width="200" align="center">

                        <el-button icon="el-icon-edit" @click="handleClick(scope.row)" type="text" size="small">查看
                        </el-button>

                        <div>
                            <el-button type="text" icon="el-icon-delete" class="red" size="small">编辑</el-button>
                        </div>

                    </template>
                </el-table-column>
            </el-table>

            <!-- 表单分页设置 -->
            <div class="pagination">
                <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex"
                    :page-size="query.pageSize" :total="pageTotal" @current-change="handlePageChange"></el-pagination>
            </div>

        </div>
    </div>

</template>

<script>
    //引入接口函数
    import {
        gitlabList
    } from "@/utils/common.js";
    export default {
        name: "basetable",
        data() {
            return {
                query: {
                    name: "",
                    address: "",
                    pageIndex: 1,
                    pageSize: 10
                },
                tableData: [],
                pageTotal: 0,

            };
        },
        mounted() {
            this.getData();
            setTimeout(function () {}.bind(this), 2000);
        },
        methods: {
            // 获取gitlba接口数据
            async getData() {

                //获取数据
                await gitlabList(this.data).then(res => {
                    this.tableData = res
                    console.log(this.tableData)
                })
            },

            //操作
            handleClick(row) {
                console.log(row);
            },

            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, "pageIndex", val);
                this.getData();
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, "pageIndex", 1);
                this.getData();
            },
            delAllSelection() {
                const length = this.multipleSelection.length;
                let str = "";
                this.delList = this.delList.concat(this.multipleSelection);
                for (let i = 0; i < length; i++) {
                    str += this.multipleSelection[i].name + " ";
                }
                this.$message.error(`删除了${str}`);
                this.multipleSelection = [];
            },

        }

    }
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }
</style>